#ifndef VIDEOANALYSISSYSTEM_VAS_CACHE_H
#define VIDEOANALYSISSYSTEM_VAS_CACHE_H

#include <string>
#include <mutex>
#include <vector>
#include <map>

#include "vas_do.h"
#include "vas_utils.h"
#include "vas_exception.h"

namespace vas {
    const char DEFAULT_NAMESPACE[] = "global";
    const char DEFAULT_GROUP[] = "default";
    const char SPLIT = '@';
    const int DEFAULT_KEEP_SIZE = 5;
    const int MIN_KEEP_SIZE = 1;
    const int MAX_KEEP_SIZE = 10000;

    static std::mutex CACHE_MTX;
    static std::map<std::string, std::vector<GCacheData>>* CACHE = nullptr;


    void CacheInit();

    std::string UUIDEncode(const std::string &key, const std::string &group, const std::string &name_space);

    void ValidNameCheck(const std::string &name);

    bool DataExistCheck(const std::string& uuid);

    void SaveValue(const std::string &key,
                   void *value,
                   int keep_size = DEFAULT_KEEP_SIZE,
                   const std::string &group = DEFAULT_GROUP,
                   const std::string &name_space = DEFAULT_NAMESPACE);

    const GCacheData &GetData(const std::string &key,
                              const std::string &group = DEFAULT_GROUP,
                              const std::string &name_space = DEFAULT_NAMESPACE);

    void *GetValue(const std::string &key,
                         const std::string &group = DEFAULT_GROUP,
                         const std::string &name_space = DEFAULT_NAMESPACE);

    const std::vector<GCacheData> &GetDataList(const std::string &key,
                                                       const std::string &group = DEFAULT_GROUP,
                                                       const std::string &name_space = DEFAULT_NAMESPACE);


    std::vector<const void *> GetValues(const std::string &key,
                                               const std::string &group = DEFAULT_GROUP,
                                               const std::string &name_space = DEFAULT_NAMESPACE);

}
#endif //VIDEOANALYSISSYSTEM_VAS_CACHE_H
